Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add "Copy Block Data" button #22

Merged
merged 13 commits into from
Apr 29, 2022

Conversation

salcode
Copy link
Owner

@salcode salcode commented Feb 27, 2022

Resolves #17

image

As outlined in the GitHub issue for this feature, there are three
different options available for adding this functionality in Gutenberg.

I have opted for the oldest (and now deprecated ClipboardButton
component).

This does come with it the disadvantage of a depreaction notice but that
seems a small price to pay for backwards compatibility.

Initially, I inteneded to use the most modern solution
useCopyToClipboard (adding in Gutenberg 10.3.0, WordPress core 5.8.x),
my thinking being that since we were importing this hook from the latest
version of the package, it would work despite running on an older
version of Gutenberg.

import { useCopyToClipboard } from '@wordpress/compose';

Nope - this fails with with the following error

TypeError
_wordpress_composer__WEBPACK_IMPORTED_MODULE_1__.useCopyToClipboard is
not a function

This only deepens my confusion around importing packages vs
destructuring them from the "wp" global as discussed in
https://salferrarello.com/wordpress-gutenberg-import-versus-destructuring-global-wp/

At this point I could add a conditional and provide two (or more) sets
of code to create this copy functionality to ensure I don't throw any
deprecation notices or I can use this older (but fully functional
technique) and be done with it.

Resolves #17
@salcode salcode marked this pull request as draft March 28, 2022 21:01
@salcode
Copy link
Owner Author

salcode commented Mar 28, 2022

Next step is to pull in the code from #21 so we can conditionally use that when useCopyToClipboard otherwise we'll fallback to the legacy CopyButton

@salcode salcode force-pushed the feat/add-copy-button-clipboard-button-17 branch from 2bfdd80 to 68d3642 Compare March 28, 2022 23:55
@salcode salcode mentioned this pull request Apr 29, 2022
salcode added 3 commits April 29, 2022 10:48
When useCopyToClipboard is present, use ModernCopyButton and when it is
not present, use LegacyCopyButton.
@salcode salcode force-pushed the feat/add-copy-button-clipboard-button-17 branch from 68d3642 to 14453a9 Compare April 29, 2022 14:48
@salcode salcode marked this pull request as ready for review April 29, 2022 15:05
@salcode salcode merged commit 40756f1 into develop Apr 29, 2022
@salcode salcode deleted the feat/add-copy-button-clipboard-button-17 branch April 29, 2022 15:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant